<template>
  <div class="mer-table-wrapper">
    <!-- 统计 -->
    <slot name="count"></slot>
    <!-- 表格 支持两种模式：直接嵌入表格项 和 配置化生成-->
    <el-table v-loading="loading" :border="border" stripe size="small" :data="tableData.records" style="width: 100%;height:100%;" highlight-current-row>
      <slot name="table"></slot>
      <el-table-column v-if="hasIndex" type="index" label="序号" width="66" fixed="left" align="center">
        <template slot-scope="scope">
          {{scope.$index+(pagination.pageIndex - 1) * pagination.pageSize + 1}}
        </template>
      </el-table-column>
      <template v-for="(item,index) in tableConfig">
        <el-table-column v-if="item.slot" :label="item.label" :prop="item.prop" :min-width="item.width" :fixed="item.fixed" :key="index" align='center'>
          <template slot-scope="{row}">
            <slot :name="item.slot" :row="row"></slot>
          </template>
        </el-table-column>
        <el-table-column v-else :label="item.label" :prop="item.prop" :min-width="item.width" :fixed="item.fixed" :key="index" align='center'></el-table-column>
      </template>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      v-show="tableData.total"
      :layout="layout"
      :total="tableData.total"
      :page-sizes="pageSizes"
      :current-page="pagination.pageIndex"
      :page-size="pagination.pageSize"
      @size-change="handleSizeChange"
      @current-change="handlePageChange"
      class="tablePagination">
    </el-pagination>
  </div>
</template>
<script>
export default {
  props: {
    // 表格配置信息
    // label ｜ prop ｜ width ｜ fixed
    tableConfig: {
      type: Array,
      default: () => {
        return []
      }
    },
    //是否显示索引
    hasIndex:{
      type: Boolean,
      default: false
    },
    border: {
      type: Boolean,
      default: true
    },
    // 表格
    loading: {
      type: Boolean,
      default: false
    },
    tableData: {
      type: Object,
      default: () => {
        return {}
      }
    },
    // 分页
    pageSizes: {
      type: Array,
      default: () => {
        return [10, 20, 50, 100, 200]
      }
    },
    layout: {
      type: String,
      default: "total, sizes, prev, pager, next, jumper"
    },
    pagination: {
      type: Object,
      default: () => {
        return { pageNo: 1, pageSize: 10 }
      }
    }
  },
  data () {
    return {

    }
  },
  methods: {
    handleSizeChange (val) {
      this.$emit('SizeChange', val)
    },
    handlePageChange (val) {
      this.$emit('PageChange', val)
    }
  }
}
</script>
<style lang="less">
.mer-table-wrapper{
  padding: 20px 5px;
  .tablePagination{
    margin: 15px 0;
    float: right;
  }
}
</style>
